module UsersHelper
  def has_logined?
    current_user_id
  end

  def has_logined_by?(user_or_id)
    user_or_id.try(:id) == current_user_id || user_or_id == current_user_id
  end

  def current_enterprise
    current_user.try(:enterprise)
  end
  
  def current_user
    User.find(current_user_id) if current_user_id
  end

  def current_user_id
    session[:current_user_id]
  end
  
  def link_to_user(user,options = {})
    options[:title] ||= "#{user.current? ? '我' : user.full_name} : #{user.mobile} "
    options[:target] ||= :_blank
    link_to (user.current? ? '我' : user.full_name), user_url(user), options
  end
end
